home *** CD-ROM | disk | FTP | other *** search
/ Sound Fx / Sound Fx.iso / Software / UNZIPED / MPW181-5 / _SETUP.1 / ibitstr.h < prev    next >
C/C++ Source or Header  |  1997-04-19  |  3KB  |  108 lines

  1. /* ibitstr.cpp
  2.  
  3.     Input bitstream class declarations */
  4.  
  5. /*
  6.  *  @(#) ibitstream.h 1.5, last edit: 6/15/94 16:55:34
  7.  *  @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
  8.  *  @(#) Berlin University of Technology
  9.  *
  10.  *  This program is free software; you can redistribute it and/or modify
  11.  *  it under the terms of the GNU General Public License as published by
  12.  *  the Free Software Foundation; either version 2 of the License, or
  13.  *  (at your option) any later version.
  14.  *
  15.  *  This program is distributed in the hope that it will be useful,
  16.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  *  GNU General Public License for more details.
  19.  *
  20.  *  You should have received a copy of the GNU General Public License
  21.  *  along with this program; if not, write to the Free Software
  22.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. // Changes made by Jeff Tsay
  26. /* 04/14/97 : Added function prototypes for new syncing and seeking
  27.    mechanisms. Also made this file portable. */
  28.  
  29. #ifndef BITSTREAM_H
  30. #define BITSTREAM_H
  31.  
  32. #ifdef __WIN32__
  33. #define STRICT
  34. #include <wtypes.h>
  35. #endif // __WIN32__
  36.  
  37. #include "all.h"
  38.  
  39. enum e_syncmode { INITIAL_SYNC, STRICT_SYNC };
  40.  
  41. class Header;    // forward declaration so we can use the type
  42.  
  43. const uint32 bufferintsize = 433;
  44.     // max. 1730 bytes per frame: 144 * 384kbit/s / 32000 Hz + 2 Bytes CRC
  45.  
  46. // Class to extract bitstrings from files:
  47. class Ibitstream
  48. {
  49.  
  50. private:
  51.  
  52. #ifdef __WIN32__
  53.   HANDLE FH;
  54. #else
  55.   // variables to access files, like file descriptors
  56.   int fd;
  57. #endif
  58.  
  59.   uint32    buffer[bufferintsize];
  60.   uint32    framesize;        // number of valid bytes in buffer
  61.   uint32    *wordpointer;    // position of next unsigned int for get_bits()
  62.   uint32    bitindex;        // number (0-31, from MSB to LSB) of next bit for get_bits()
  63.   uint32 syncword;
  64.   BOOL   single_ch_mode;
  65.  
  66.   int32  current_frame_number;
  67.   int32  last_frame_number;
  68.  
  69. public:
  70.  
  71.   Ibitstream(const char *filename);
  72.   ~Ibitstream();
  73.  
  74.   BOOL    get_header(uint32 *headerstring , enum e_syncmode syncmode);
  75.         // get next 32 bits from bitstream in an unsigned int,
  76.         // returned value False => end of stream
  77.   BOOL    read_frame(uint32 bytesize);
  78.         // fill buffer with data from bitstream, returned value False => end of stream
  79.   uint32    get_bits(uint32 number_of_bits);
  80.         // read bits (1 <= number_of_bits <= 16) from buffer into the lower bits
  81.         // of an unsigned int. The LSB contains the latest read bit of the stream.
  82.  
  83.   void   set_syncword(uint32 syncword0);
  84.           // Set the word we want to sync the header to, in
  85.       // Big-Endian byte order
  86.  
  87.   int32  current_frame() { return(current_frame_number); }
  88.   int32  last_frame()    { return(last_frame_number); }
  89.  
  90.   // Stream searching routines (Jeff Tsay)
  91.  
  92.   uint32 file_size();
  93.         // Returns the size, in bytes, of the input file.
  94.  
  95. #ifdef SEEK_STOP
  96.  
  97.   BOOL   seek(int32 frames, int32 frame_size);
  98.         // Seeks frames for 32 kHz and 48 kHz (non-padded) files
  99.  
  100.   BOOL   seek_pad(int32 frames, int32 frame_size,
  101.                           Header *header, uint32 *offset);
  102.         // Seeks frames for 44.1 kHz (padded) files
  103. #endif
  104.  
  105. };
  106.  
  107. #endif
  108.